package pl.edu.mimuw.mas.agent.behaviour.helicopter.verification;

import pl.edu.mimuw.mas.agent.HelicopterAgent;
import pl.edu.mimuw.mas.agent.behaviour.MutableTimedBehaviour;
import pl.edu.mimuw.mas.util.Move;
import pl.edu.mimuw.mas.util.Position;
import pl.edu.mimuw.mas.util.PositionHelper;
import pl.edu.mimuw.mas.util.Time;

/**
 * Zachowanie śledzenia ruchu łosia. Agent zaczyna poruszać się nad łosiem jeśli
 * ten jest w jego pobliżu.
 */
public class FollowDeerBehaviour extends MutableTimedBehaviour {
	private static final long serialVersionUID = 8129003954027294678L;

	private Position dest;

	public FollowDeerBehaviour(HelicopterAgent agent) {
		super(agent, Time.HELICOPTER_STEP);
	}
	
	protected void onTick() {
		HelicopterAgent ha = (HelicopterAgent) myAgent;
		ha.setFollowColor();

		dest = PositionHelper.followDeerInRange(ha);
		int vx = dest.x - ha.getPosition().x;
		int vy = dest.y - ha.getPosition().y;
		int max = Math.max(Math.abs(vx), Math.abs(vy));

		PositionHelper.fly(ha, new Move((int) Math.round((double) vx / max), (int) Math.round((double) vy / max)));
	}
}
